<?php

defined("_ARKN_EXEC") or exit("no no, mr. superman no here");
($_SESSION["roleid"] == Roles::Secretary) or exit("you almost got away with it");
require ROOT_FOLDER . "/php/pages/menu_strip.php";
require_once ROOT_FOLDER . "/php/scripts/site_dep_scripts/Department.php";
require_once ROOT_FOLDER . "/php/scripts/course_scripts/Course.php";
$departments = $department->departments();

print("<script type='text/javascript'>");
print("var courses = new Array();\n");
for($i = 0; $i < count($departments); $i++) {
	$depCourses = $course->coursesFromDep($departments[$i]->id);
	if($i == 0)
		$firstDepCourses = $depCourses;
	print("var c$i = new Array();\n");
	for($j = 0; $j < count($depCourses); $j++) {
		print("var c$i$j = new Array();\n");
		print("c$i$j.push(\"" . htmlEsc($depCourses[$j]["courseid"]) . "\");\n");
		print("c$i$j.push(\"" . htmlEsc($depCourses[$j]["name"]) . "\");\n");
		print("c$i$j.push(\"" . htmlEsc($depCourses[$j]["credits"]) . "\");\n");
		print("c$i.push(c$i$j);\n");	
	}
	print("courses.push(c$i);\n");
}
print("</script>");

print('<div style="width: 100%; text-align: center;">');						// main div
print('<div style="display: inline-block;">');									// centering div	

print("<br/><br/><p>Department:&nbsp;&nbsp;");
print('<select id="depSelect">');
foreach($departments as $row) {
	print('<option value="' . htmlEsc($row->id) . '">');
	print(htmlEsc($row->name));
	print("</option>");
}
print("</select>");

print('<br/><table cellpadding="0" cellspacing="0" id="coursesTable" class="db-table">');
print("<tr>");
print("<th>ID</th>");
print("<th>Name</th>");
print("<th>Credits</th>");
print("</tr>");

foreach($firstDepCourses as $row) {
	print('<tr class="normalCourseRow">');
	print("<td>" . htmlEsc($row["courseid"]) . "</td>");
	print("<td>" . htmlEsc($row["name"]) . "</td>");
	print("<td>" . htmlEsc($row["credits"]) . "</td>");
	print("</tr>");
}
print("</table>");

print("</div>");																// centering div
print("</div>");																// main div

?>